<template>
  <div class="contain">
    <!-- 搜索 -->
    <el-form :model="query" ref="queryForm" :inline="true" class="top-search" label-position="left">
      <el-form-item label="关键词" prop="fitmentCase">
        <el-input v-model="query.fitmentCase" placeholder="请输入" clearable />
      </el-form-item>
      <el-form-item label=" ">
        <el-button type="primary" @click="getList()">查询</el-button>
      </el-form-item>
    </el-form>
    <!-- 操作菜单 -->
    <div class="mid-action">
      <div>
        <el-button type="primary" size="mini" @click="creatItem('creat')">添加</el-button>
      </div>
    </div>
    <!-- 表格列表 -->
    <el-table v-loading="loading" :data="list">
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="头像" align="center" prop="portrait" width="140px">
        <template slot-scope="scope">
          <el-image :src="scope.row.portrait" fit="cover" style="width:80px;height:80px;"></el-image>
        </template>
      </el-table-column>
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="手机号" align="center" prop="phone" />
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="操作" align="center" width="180">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="creatItem('edit', scope.row)">审核</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="query.pageNum"
      :limit.sync="query.pageSize"
      @pagination="getList()"
    />
    <!-- 编辑表单 -->
    <el-dialog :title="formTtile == 'creat' ? '添加' : '编辑'" :visible.sync="editFormShow">
      <el-form class="edit_form" :model="form" ref="form" label-width="100px" label-position="right">
        <el-form-item label="头像" prop="portrait">
            <img v-if="form.portrait" :src="form.portrait" class="avatar">
        </el-form-item>
        <el-form-item label="邮箱" prop="mailbox">
          <el-input class="input" v-model="form.mailbox" disabled placeholder="请输入" clearable  />
        </el-form-item>
        <el-form-item label="姓名" prop="name">
          <el-input class="input" v-model="form.name" disabled placeholder="请输入" clearable  />
        </el-form-item>
        <el-form-item label="电话" prop="phone">
          <el-input class="input" v-model="form.phone" disabled placeholder="请输入" clearable  />
        </el-form-item>
        <el-form-item label="职位" prop="post">
          <el-input class="input" v-model="form.post" disabled placeholder="请输入" clearable  />
        </el-form-item>
        <el-form-item label="个人介绍" prop="selfIntroduction">
          <el-input class="input" v-model="form.selfIntroduction" disabled placeholder="请输入" clearable  />
        </el-form-item>
        <el-form-item label="地址" prop="site">
          <el-input class="input" v-model="form.site" disabled placeholder="请输入" clearable  />
        </el-form-item>
        <el-form-item label="微信二维码" prop="wxYard">
            <img v-if="form.wxYard" :src="form.wxYard" class="avatar">
        </el-form-item>
        <el-form-item label="审核状态">
          <el-radio-group v-model="form.amendCheck" size="small">
            <el-radio :label="'0'" border>待审核</el-radio>
            <el-radio :label="'1'" border>审核通过</el-radio>
            <el-radio :label="'2'" border>审核拒绝</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submit()">提交</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { getCardExaminedList, updateCardExaminedInfoStatus, getCardExaminedInfo } from "@/api/eh-api";
export default {
  data() {
    return {
        // 遮罩层
        loading: false,
        // 总条数
        total: 0,
        // 查询参数
        query: {
            pageNum: 1,
            pageSize: 10,
            fitmentCase: undefined,
        },
        list:[],
        editFormShow:false,
        formTtile:'creat',
        form:{
          amendCheck: "",
          checkCardId: null,
          company: null,
          companyProfile: "",
          createTime: "",
          delFlag: "",
          id: "",
          mailbox: null,
          name: null,
          phone: null,
          portrait: null,
          post: null,
          selfIntroduction: null,
          sign: null,
          site: null,
          updateTime: null,
          wxYard: null,
        },
    };
  },
  created() {
    this.getList()
  },
  methods: {
    /**
     * 获取列表
     */
    getList() {
      this.loading = true;
      getCardExaminedList(this.query)
        .then(({ rows, total }) => {
          this.list = rows;
          this.total = parseInt(total);
          this.loading = false;
          this.ids = [];
        })
        .catch(() => {
          this.loading = false;
        });
    },

    /**
     * 添加
     */
    creatItem:function(title,item) {
      this.formTtile = title
      this.editFormShow = true
      if( title == 'edit' ){ //编辑
        getCardExaminedInfo({
          id: item.id
        }).then( res => {
          if( res.code == 200 ){
            for( let key in this.form ){
              this.form[key] = res.data[key]
            }
            console.log(this.form)
          }else{
            this.$message.error(res.msg);
          }
        })
      }
    },
    /**
     * 提交表单
     */
    submit:function(params) {
        console.log( this.form )
        let form = {}
        form.cardId = this.form.id
        form.check = this.form.amendCheck
        updateCardExaminedInfoStatus(form).then( res => {
            if( res.code == 200 ){
              this.$message({
                message: '编辑成功',
                type: 'success'
              });
              this.getList();
            }else{
              this.$message.error(res.msg);
            }
          })

        this.editFormShow = false
    },
  },
};
</script>

<style lang="scss" scoped>
.mid-action {
  display: flex;
  justify-content: space-between;
  margin: 10px 0;
  align-items: center;
  .total {
    background-color: rgba(65, 133, 244, 0.1);
    border: 1px solid rgba(65, 133, 244, 0.2);
    border-radius: 3px;
    font-size: 14px;
    min-height: 32px;
    line-height: 32px;
    padding: 0 12px;
    color: #606266;
  }
  .num {
    color: #00f;
  }
}
.thumbnail {
  width: 160px;
  height: 80px;
}
.input{
  width: 80%;
}

/**头像 */
.avatar-uploader /deep/.el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}
.avatar-uploader /deep/.el-upload:hover {
    border-color: #409EFF;
}
.avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 128px;
    height: 128px;
    line-height: 128px;
    text-align: center;
}
.avatar {
    width: 128px;
    height: 128px;
    display: block;
}

.detail{
  max-height: 500px;
  overflow: scroll;
}

.detail_item{
  width: 80%;
  display: block;
}
</style>
